<?php

namespace App\Http\Controllers;

use App\Business\BLL\LuckmoneyBLL;
use App\Models\LuckMoneyLog;
use App\Models\UserWallet;
use Illuminate\Http\Request;

class LuckMoneyController extends Controller
{
    public function confirm()
    {
        $id = request()->input('id', 0);

        $luckmoneyBLL = new LuckmoneyBLL;
        $luckMoney = $luckmoneyBLL->confirmLuckMoney($id);
        return response()->json($luckMoney);
    }

    public function getAmount()
    {
        $userId = request()->input('user_id', 0);
        $amount = UserWallet::where('user_id', $userId)->first();
        if (!$amount) {
            $amount = ['money' => 0];
        }
        return response()->json(['recode' => 1, 'amount' => $amount]);
    }

    public function getLuckMoneyList()
    {
        $pn = request()->input('pn', config('api.page_num'));
        $userId = request()->input('user_id', 0);
        $list = LuckMoneyLog::where([['user_id', $userId], ['status', 2]])
            ->orderBy('created_at', 'desc')
            ->paginate($pn);
        return response()->json(['recode' => 1,
            'data' => ['last_page' => $list->lastPage()
                , 'page' => $list->currentPage()
                , 'list' => $list->items()]]);

    }
}
